package java期末练习.text50;

class Student {
    int id;
    String name;
    Student(int id, String name) {

        this.id = id;

        this.name = name;

    }

    @Override
    public String toString() {
        return "Student{" +

                "id=" + id +

                ", name='" + name + '\'' +

                '}';
    }
}

public class ArrayLIst {
    public static void main(String[] args) {

        java.util.ArrayList<Student> students = new java.util.ArrayList<>();

        students.add(new Student(1, "张三"));

        students.add(new Student(2, "李四"));

        students.add(new Student(3, "王五"));

        for (Student student : students) {

            System.out.println(student);
        }

        for (Student student : students) {

            if (student.name.equals("张三")) {

                student.name = "张三丰";
                break;
            }
        }


        System.out.println("修改姓名后:");

        for (Student student : students) {

            System.out.println(student);
        }

        students.removeIf(student -> student.name.equals("王五"));

        System.out.println("删除王五后:");

        for (Student student : students) {

            System.out.println(student);
        }
    }
}